
<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>元数据</title>
    <link href="/static/devtools30/layui-v2.5.6/css/layui.css" rel="stylesheet" />
    <link href="/static/devtools30/css/devindexbase.css" rel="stylesheet" />
    <link href="/static/devtools30/layui-v2.5.6/ext/soulTable/soulTable.css" rel="stylesheet"/>

    <script src="/static/devtools30/js/jquery-1.11.2.min.js" type="text/javascript"></script>
    <script src="/static/devtools30/layui-v2.5.6/layui.all.js" type="text/javascript"></script>
    <script src="/static/devtools30/layui-v2.5.6/layui.js" type="text/javascript"></script>
    <script src="/static/devtools30/js/devtoolCommon.js" type="text/javascript"></script>

    <link href="/static/devtools30/js/plugins/codemirror-5.14.2/theme/eclipse.css" rel="stylesheet" type="text/css" />
    <link href="/static/devtools30/js/plugins/codemirror-5.14.2/lib/codemirror.css" rel="stylesheet" />
    <script src="/static/devtools30/js/plugins/codemirror-5.14.2/lib/codemirror.js" type="text/javascript"></script>
    <script src="/static/devtools30/js/plugins/codemirror-5.14.2/mode/sql/sql.js" type="text/javascript"></script>
    <script src="/static/devtools30/js/plugins/codemirror-5.14.2/mode/javascript/javascript.js" type="text/javascript"></script>

    <style>
        /*顶部容器*/
        .tophead {
            height: 32px;
            border-bottom: 1px solid #F7F7F7;
            padding: 0 5px;
        }
        /*顶部输入框，下拉框去掉layui默认边距*/
        .tophead .layui-form-item {
            margin-bottom: 0px!important;
        }
        /*顶部输入框，下拉框左边文本样式*/
        .tophead .layui-form-label {
            padding: 0;
            line-height: 25px;
            width: auto;
        }
        /*顶部form块样式*/
        .tophead .layui-input-block {
            margin-left: 34px;
            min-height: 26px;
        }
        /*顶部输入框，下拉框设置高度*/
        .tophead .layui-input,
        .layui-select {
            height: 25px;
        }
        /*顶部下拉框设置子项高度*/
        .tophead .layui-form-select dl {
            top: 26px;
            padding: 0;
        }
        /*顶部下拉框设置子项内容高度*/
        .tophead .layui-form-select dl dd,
        .layui-form-select dl dt {
            line-height: 24px;
        }
        .tophead .layui-form-item {
            width: 165px;
            padding: 5px;
        }
        /*顶部下拉框图标大小*/
        .tophead .layui-form-select .layui-edge {
            border-width: 4px;
        }
        /*搜索框左边距*/
        .tophead .search .layui-input-block {
            margin-left: 32px;
        }

        /*表格-----------------------------------*/

        /*表格字体大小*/
        .layui-table td,
        .layui-table th {
            font-size: 11px!important;
        }
        /*表格边距*/

        .layui-table,
        .layui-table-view {
            margin: 0;
        }
        /*按钮高度大小*/
        .layui-btn {
            height: 26px;
            line-height: 26px;
            font-size: 11px;
        }
        /*按钮组-------------------------------*/
        /*按钮组左边框*/
        .layui-btn-group .layui-btn-primary:first-child {
            border-left: 1px solid #c9c9c9!important;
        }
        /*按钮组边框*/
        .layui-btn-group .layui-btn {
            border-left: 1px solid rgba(255, 255, 255, .5)!important;
        }
    </style>

</head>
<body>
<div style="height: 100%;background: #F7F7F7;">
    <div class="flex flex-align-center flex-jusity-betreen tophead backgroundf">
        <div class="flex flex-align-center">
            <form class="layui-form" lay-filter="formTest">
            <div class="layui-form flex flex-align-center" >
                <div class="layui-form-item">
                    <label class="layui-form-label">分类</label>
                    <div class="layui-input-block">
                        <select id="selType" lay-filter="selType" name="selType">

                        </select>
                    </div>
                </div>
                <div class="layui-form-item" style="width: 320px;">
                    <label class="layui-form-label">类型</label>
                    <div class="layui-input-block">
                        <input type="checkbox" checked lay-skin="primary" class="modeltype" name="modeltype" th:each="c:${modelTypeList}" th:value="${c.value}" th:title="${c.value}">
                    </div>
                </div>
                <div class="layui-form-item marginleft10 search">
                    <label class="layui-form-label">查询</label>
                    <div class="layui-input-block">
                        <input type="text" id="searchValue"  name="searchValue" placeholder="请输入表代码/表名称" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <button type="button" onclick="getTableList()" class="layui-btn layui-btn-sm layui-btn-normal marginleft10">确定</button>
            </div>
            </form>
        </div>
        <div class="layui-btn-group btns">
            <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" name='101'>分类维护</button>
            <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" name='102'>模型维护</button>
            <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" name='103'>新增元数据</button>
            <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" name='104'>数据库导入</button>
            <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" name='105'>更新SQL</button>
        </div>
    </div>
    <div class="flex flex-jusity-betreen " style="height:100%;width: 100%;background: #F7F7F7;padding: 3px 0;">
        <div class="backgroundf">
            <table  id="mygrid" lay-filter="mygrid"></table>
        </div>
        <div class="backgroundf" >
            <table  id="mygrid2"  lay-filter="mygrid2"></table>
        </div>
    </div>

</div>
<div id="defaultValue_div" style="display: none;">
    <div class="div_border">
        <div class="div_h">

                     <textarea id="zbsql"
                               type="text" placeholder=" " name="zbsql"  style=" display: block; width:435px; "></textarea>
        </div>
    </div>

</div>

<script>
    var height = dlCommon.getWinHeight();
    var width=dlCommon.getWinWidth();
    var selTableId="";
    var editor = CodeMirror.fromTextArea(document.getElementById("zbsql"), {
        lineNumbers: true,
        matchBrackets: true,
        lineWrapping:true,
        mode: "text/x-plsql"
    });
    editor.setOption("theme", "eclipse");
    editor.setSize('90%', '300px');

    layui.config({
        base: '/static/devtools30/layui-v2.5.6/ext/',// 第三方模块所在目录
        version: 'v1.5.10' // 插件版本号
    }).extend({
        soulTable: 'soulTable/soulTable',
        tableChild: 'soulTable/tableChild',
        tableMerge: 'soulTable/tableMerge',
        tableFilter: 'soulTable/tableFilter',
        excel: 'soulTable/excel',
        dltable: 'treegrid/dltable',
        treeGrid:'treegrid/treeGrid'
    });
    layui.use(['form', 'table','soulTable', 'jquery','treeGrid','layer'], function(){
        $(function() {

            initGrid();

            initEvent();

            bindForm();

            getTableList();

        })
    });


    //数据表
    function getTableList(){

        var modeltype='';
        $('.modeltype:checked').each(function() {
            modeltype=$(this).val()+","+modeltype;
        });

        var data={
            serach:$("#searchValue").val(),
            typeid:$("#selType").val(),
            modeltype:modeltype
        };

        dlCommon.getJSON("/DevtModelMetadataTableController/getAllResTreeGrid",data,function(res){
            layui.treeGrid.render({
                id:"mygrid"
                ,elem: '#mygrid'
                ,height: height-36
                , width: width*0.26
                , size: 'sm'//小尺寸的表格
                ,idField:'id'
                ,data:res&&res.data?(res.data):[]
                ,treeId:'id'//树形id字段名称
                ,treeUpId:'pId'//树形父id字段名称
                ,treeShowName:'flmc'//以树形式显示的字段
                ,cols: [
                    [
                        {field:'flmc',width:160,filter:true, title: '模型分类'},
                        {field:'name', edit:'text',width:160,filter:true, title: '模型名称'},
                        {field:'viewcode', edit:'text',width:160,filter:true, title: '视图代码'}
                    ]]
                ,page:false
            });
        });
        //单击表格
        layui.treeGrid.on('row(mygrid)', function(obj){
            selTableId=obj.data.id;
            getFieldList();
        });
    }
    //元数据字段
    function getFieldList(){
        if(!selTableId){
            return;
        }
        var data={
            tableid:selTableId
        };
        layui.table.reload("mygrid2",{
            url:"/DevtModelMetadataFieldController/getAll",
            where:data,
            loading:true,
        });
    }

    function bindForm(){
        var valueForm=layui.form.val('formTest');
        dlCommon.getJSON("/DevtModelMetadataType/getAll",{},function(res){
            var str='<option value="">全部</option>';
            $(res.data).each(function(i,d){
                str+='<option value="'+d.id+'">'+d.flmc+'</option>';
            })
            $("#selType").html(str);
            layui.form.render();
            layui.form.val('formTest',valueForm);
        });

    }
    //初始化grid
    function initGrid(){

        //第2个实例
        layui.table.render({
            elem: '#mygrid2',
            height: height-36,
            width: width*0.735,
            size: 'sm', //小尺寸的表格
            loading:false,
            page: false, //开启分页
            cols: [
                [ //表头
                    { field: 'xh', title: '序号', width: 80, fixed: 'left' },
                    { field: 'fieldName', title: '中文名称',filter:true, sort: true, width: 120 },
                    { field: 'fieldCode', title: '字段代码',filter:true, sort: true, width: 150, },
                    { field: 'pkey', title: '主键',  width: 80,templet: function(d){
                        var str="否";
                        if(d.pkey==1){
                            str="是"
                        }
                        return str;
                        } },
                    { field: 'fieldType', title: '字段类型',filter:true, sort: true, width: 100, },
                    { field: 'typeLength', title: '字段长度',filter:true, sort: true, width: 100 },
                    { field: 'typeZeroLength', title: '小数位数',filter:true, sort: true, width: 100, },
                    { field: 'bz', title: '备注' },
                    { field: 'opera', title: '操作', width: 120,templet: function(d){
                        var str="";
                        str += '<button type="button" onclick="editField(\''+d.id+'\')" class="layui-btn layui-btn-normal layui-btn-xs layui_edit_btn">修改</button>';
                        str += '<button type="button" onclick="delField(\''+d.id+'\')" class="layui-btn layui-btn-danger layui-btn-xs layui_edit_btn">删除</button>';

                        return str;
                        }
                    }
                ]
            ],
            filter:{
                bottom:false,
            },
            done: function () {
                layui.soulTable.render(this)
            }
        });
    }
    //初始化事件
    function initEvent(){
        //按钮点击
        $('.btns>button').on('click', function() {
            var names = $(this)[0].name;
            if(names == '101') {
                dlCommon.layeropen(900,height*0.8,'分类维护','/DevtModelMetadataType/toList',{
                    end:function () {
                        bindForm();
                        getTableList();
                        getFieldList();
                    }
                })
                return;
            }
            if(names == '102') {
                dlCommon.layeropen(1024,height*0.8,'模型维护','/V_DevtModelMetadataTableController/toList',{
                    end:function () {
                        bindForm();
                        getTableList();
                        getFieldList();
                    }
                })
            return;
            }
            if(!selTableId){
                dlCommon.layerInfo('请选择模型');
                return;
            }
            if(names == '103') {

                dlCommon.layeropen(900,height*0.8,'新增元数据','/V_DevtModelMetadataFieldController/edit?formId='+selTableId,{
                    end:function () {
                        bindForm();
                        getTableList();
                        getFieldList();
                    }
                })

            }
            if(names == '104') {

                dlCommon.layeropen(width*0.8,height*0.8,'数据库导入','/V_DevtModelMetadataFieldController/toFieldEditFromDb?formId='+selTableId,{
                    end:function () {
                        bindForm();
                        getTableList();
                        getFieldList();
                    }
                })
            }
            if(names == '105') {
                showUpdateSql();
            }
            //console.log($(this)[0].name)
        })

    }
    function editField(id){
        dlCommon.layeropen(800,height*0.8,'新增元数据','/V_DevtModelMetadataFieldController/edit?id='+id+'&formId='+selTableId,{
            end:function () {
                bindForm();
                getTableList();
                getFieldList();
            }
        })
    }
    function delField(id) {
        if(!id){
            return;
        }
        dlCommon.layerConfirm("是否确定删除该表字段？",function(){
            dlCommon.getJSON("/DevtModelMetadataFieldController/delete",{id:id},function(res){
                if(!res.success){
                    dlCommon.layerError(res.msg);
                    return;
                }
                getFieldList();
            })
        })

    }
    function showUpdateSql(){
        if(!selTableId){
            dlCommon.layerInfo("请选择表.");
            return;
        }
        dlCommon.layerOpenDiv(600,350,'复制更新SQL',$('#defaultValue_div'))

        editor.setValue("");

        var jsonData={};
        dlCommon.getJSON("/DevtModelMetadataTableController/dbSyncInter",{formId:selTableId},function(res){
            editor.setValue(res.data);

        },true);
    }

</script>
</body>
</html>
